package ch.uzh.ifi.seal.ssqa.importer.code;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import ch.uzh.ifi.seal.ssqa.model.DiagramComponent;

public class SubEntityParser {
	
	Map<String, String> sources = new HashMap<String, String>();
	
	Map<String, String> subentities = new HashMap<String, String>();
	
	public SubEntityParser(List<DiagramComponent> diagramSources){
		for(DiagramComponent diagramComponent : diagramSources){
			for(String componentSources : diagramComponent.getSourcePaths()){
				this.sources.put(componentSources, diagramComponent.getIdentifier());
			}
		}
	}
	
	public Map<String, String> getSubEntities(){
		Vector<String> strings = new Vector<String>();
		strings.addAll(this.sources.keySet());
		
		while(strings.size() > 0){
			String elementUnderCheck = strings.remove(0);
			for(String checker : strings){
				if(elementUnderCheck.contains(checker)){
					this.subentities.put(elementUnderCheck, this.sources.get(elementUnderCheck));
				} else if(checker.contains(elementUnderCheck)){
					this.subentities.put(checker, this.sources.get(checker));
				}
			}
		}
		this.printSources();
		return this.subentities;
	}
	
	public void printSources(){
		for(String source : this.subentities.keySet()){
			System.out.println(source + " / " + this.subentities.get(source));
		}
	}
}
